package com.wooophone.mpyeah.entity;

import java.util.ArrayList;
import java.util.List;

import com.wooophone.common.util.JsonSfUtil;
import com.wooophone.mpyeah.util.SystemUtil;

/**
 * 品牌分类实体对象
 * 
 * @author MingliC
 * 
 */
public class BrandCategory extends BaseEntity {

	/** 父级ID */
	private String parentId;
	/** 评分字段列表 */
	private String gradeField;
	/** 所有评分字段(包括父级) */
	private List<Object> gradeFieldList;
	/** 分类Icon */
	private String icon;
	/** 排序 */
	private int sortOrder;
	
	/** 该分类下的所有品牌 */
	private List<Brand> brands;
	/** 该分类的父级分类 */
	private BrandCategory parent;
	/** 该分类的子级分类 */
	private List<BrandCategory> children;
	
	/**当前分类评分字段*/
	private List<Object> nonceGrandeField;

	/** Icon真实路径 */
	private String iconAbsolutePath;
	
	/** Icon真实路径 */
	public String getIconAbsolutePath() {
		
		if(iconAbsolutePath==null){
			if(icon!=null){
				iconAbsolutePath=SystemUtil.imageBasePath+icon;
			}else{
				iconAbsolutePath=null;
			}
		}
		
		return iconAbsolutePath;
	}

	/** Icon真实路径 */
	public void setIconAbsolutePath(String iconAbsolutePath) {
		this.iconAbsolutePath = iconAbsolutePath;
	}

	/** 该分类下的所有品牌 */
	public List<Brand> getBrands() {
		return brands;
	}

	/** 该分类下的所有品牌 */
	public void setBrands(List<Brand> brands) {
		this.brands = brands;
	}

	/** 该分类的父级分类 */
	public BrandCategory getParent() {
		return parent;
	}

	/** 该分类的父级分类 */
	public void setParent(BrandCategory parent) {
		this.parent = parent;
	}

	/** 父级ID */
	public String getParentId() {
		return parentId;
	}

	/** 父级ID */
	public void setParentId(String parentId) {
		this.parentId = parentId;
	}

	/** 评分字段列表 */
	public String getGradeField() {
		return gradeField;
	}

	/** 评分字段列表 */
	public void setGradeField(String gradeField) {

		this.gradeField = gradeField;
	}

	/** 分类Icon */
	public String getIcon() {
		return icon;
	}

	/** 分类Icon */
	public void setIcon(String icon) {
		this.icon = icon;
	}

	/** 子级分类 */
	public List<BrandCategory> getChildren() {
		return children;
	}

	/** 子级分类 */
	public void setChildren(List<BrandCategory> children) {
		this.children = children;
	}

	/** 评分字段数组 */
	public List<Object> getGradeFieldList() {

		if (gradeFieldList == null) {
			Object[] fields = JsonSfUtil.toArray(getGradeField());
			gradeFieldList = new ArrayList<Object>();
			if (fields != null) {
				for (Object object : fields) {
					gradeFieldList.add(object);
				}
			}
			if (getParent() != null) {
				List<Object> parentList = parent.getGradeFieldList();
				if (parentList != null) {
					gradeFieldList.addAll(parentList);
				}
			}
		}

		return gradeFieldList;
	}

	/** 评分字段数组，只需添加当前分类 */
//	public void setGradeFieldList(List<Object> gradeFieldList) {
//
//		gradeField = JsonSfUtil.toJsonByJsonLib(gradeFieldList);
//
//		if (getParent() != null) {
//			List<Object> parentList = parent.getGradeFieldList();
//			if (parentList != null) {
//				gradeFieldList.addAll(parentList);
//			}
//		}
//
//		this.gradeFieldList = gradeFieldList;
//	}

	public List<Object> getNonceGrandeField() {
		if (nonceGrandeField == null) {
			Object[] fields = JsonSfUtil.toArray(getGradeField());
			nonceGrandeField = new ArrayList<Object>();
			if (fields != null) {
				for (Object object : fields) {
					nonceGrandeField.add(object);
				}
			}
			
		}
		return nonceGrandeField;
	}

	public void setNonceGrandeField(List<Object> nonceGrandeField) {
		
		this.nonceGrandeField = nonceGrandeField;
	}

	
	public int getSortOrder() {
		return sortOrder;
	}

	public void setSortOrder(int sortOrder) {
		this.sortOrder = sortOrder;
	}

	public void setGradeFieldList(List<Object> gradeFieldList) {
		this.gradeFieldList = gradeFieldList;
	}

	
}
